package com.fancy.learncenter.ui.view;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.support.v7.widget.CardView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.common.MyApplication;

/**
 * Created by Hyy on 2017/3/10.
 */

public class PromptPopupWindow extends BasePopupWindow {
    View popopView;

    View locationView;

    Activity mContext;

    private AnimatorSet animSet;
    private ObjectAnimator animatorAlpha;
    private ObjectAnimator animatorScalex;

    TextView prompt_title;
    TextView btn_quit;
    TextView btn_cancel;

    public PromptPopupWindow(Activity mContext, View locationView) {
        super(mContext);
        this.mContext = mContext;
        this.locationView = locationView;
        popopView = LayoutInflater.from(MyApplication.context).inflate(R.layout.layout_prompt_dialog, (ViewGroup) locationView, false);
        prompt_title = popopView.findViewById(R.id.prompt_title);
        btn_cancel = popopView.findViewById(R.id.btn_cancel);
        btn_quit = popopView.findViewById(R.id.btn_quit);

        initPopupWionw();

    }

    private void initPopupWionw() {

        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);

        setOutsideTouchable(true);

        setContentView(popopView);

        popopView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        btn_quit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.confirm();
                dismiss();
            }
        });

        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.cancle();
                dismiss();
            }
        });

    }


    public void setPromptTitle(String title) {
        prompt_title.setText(title);
    }

    @Override
    public void showPopupWindow() {
        super.showPopupWindow();

        showAtLocation(locationView, Gravity.CENTER, 0, 0);
    }

    public CallBack getCallBack() {
        return callBack;
    }

    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }

    private CallBack callBack;

    public interface CallBack {
        abstract void confirm();

        abstract void cancle();
    }
}
